package com.spring.tx.dao;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class BookDao {
    @Autowired
    JdbcTemplate jdbcTemplate;
    /**
     * 减余额
     */
    public void updateBanlance(String userName,int price){

        String sql = "UPDATEAA account SET balance = balance - ? WHERE username = ?";
        jdbcTemplate.update(sql,price,userName);
    }

    /**
     * 获取某一本图书的价格
     */
    public int getPrice(String isbn){
        String sql = "select price from book where isbn = ?";
        int update = jdbcTemplate.queryForObject(sql,Integer.class,isbn);
        return update;
    }

    /**
     * 减去库存
     */
    public void updateStock(String isbn){
        String sql = "update book_stock set stock=stock-1 where isbn=?";
        jdbcTemplate.update(sql,isbn);
    }
}
